package com.budweiser.user.dao;

import com.budweiser.model.user.Permission;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * 角色权限关系<br>
 * 角色和权限是多对多关系，sys_role_permission是中间表
 *
 * @author 刘恒福
 */
@Mapper
public interface RolePermissionDao {

	Set<Permission> findPermissionsByRoleIds(@Param("roleIds") Set<Long> roleIds);

	/***
	 * 根据角色Id查询权限
	 * 
	 * @param roleid
	 * @return
	 */
	@Select("select p.id as id,p.`name` as `name`,if(r.permissionId is null,false,true) as deleteStatus from sys_permission p left join sys_role_permission r on p.id = r.permissionId and r.roleId = #{roleid}")
	List<Permission> getPermissionByRoleid(Long roleid);

	/***
	 * 根据角色id，权限id查询角色权限表
	 * 
	 * @param roleid
	 * @param permissionId
	 */
	void delete(@Param("roleid") Long roleid, @Param("permissionId") Long permissionId);

	/***
	 * 新增角色权限表
	 * 
	 * @param roleid
	 * @param
	 */
	@Insert("insert into sys_role_permission(roleId, permissionId) values(#{roleId}, #{permissionId})")
	void save(@Param("roleId") Long roleid, @Param("permissionId") Long permissionId);


}
